package com.bdq.content.api.client;

import cn.hutool.core.convert.Convert;
import com.bdq.common.entity.common.CommonResult;
import com.bdq.common.entity.common.PageResult;
import com.bdq.common.feign.content.ContentFeign;
import com.bdq.common.feign.content.param.ContentQueryParam;
import com.bdq.common.feign.content.param.ContentSearchParam;
import com.bdq.common.feign.content.param.UserPostPageParam;
import com.bdq.common.feign.content.vo.ContentListVO;
import com.bdq.content.application.model.dto.ContentListAppDTO;
import com.bdq.content.application.model.query.ContentQueryQry;
import com.bdq.content.application.model.query.ContentSearchQry;
import com.bdq.content.application.model.query.UserPostPageQry;
import com.bdq.content.application.service.ContentQueryService;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author malei
 * @date 2024-05-26 11:16
 */
@RestController
public class ContentFeignImpl implements ContentFeign {

    @Resource
    private ContentQueryService contentQueryService;

    @Override
    public CommonResult<List<ContentListVO>> listContent(Long userId, List<Long> contentIds) {
        List<ContentListAppDTO> appDTOList = contentQueryService.listContent(userId, contentIds);
        return CommonResult.success(Convert.toList(ContentListVO.class, appDTOList));
    }

    @Override
    public CommonResult<PageResult<Long>> contentSearch(ContentSearchParam param) {
        PageResult<Long> pageResult = contentQueryService.contentSearch(Convert.convert(ContentSearchQry.class, param));
        return CommonResult.success(pageResult);
    }

    @Override
    public CommonResult<PageResult<Long>> contentQuery(ContentQueryParam param) {
        PageResult<Long> pageResult = contentQueryService.contentQuery(Convert.convert(ContentQueryQry.class, param));
        return CommonResult.success(pageResult);
    }

    @Override
    public CommonResult<PageResult<Long>> pageUserPost(UserPostPageParam param) {
        PageResult<Long> pageResult = contentQueryService.pageUserPost(Convert.convert(UserPostPageQry.class, param));
        return CommonResult.success(pageResult);
    }
}
